//
//  ListViewController.m
//  我的图书馆
//
//  Created by 孙  路 on 15-1-5.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ListViewController.h"

#import "ListTableViewCell.h"
//文件夹管理界面
#import "CustomNewFolderViewController.h"
@interface ListViewController ()

@end

@implementation ListViewController
- (void)dealloc
{
    [_tableArray release];
    [_secondArray release];
    [_bigDic release];
    [_tableV release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];
        self.secondArray = [NSMutableArray array];
        self.bigDic = [NSMutableDictionary dictionary];

        self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 50, self.view.frame.size.height) style:UITableViewStyleGrouped];
        
        [_tableV registerClass:[ListTableViewCell class] forCellReuseIdentifier:@"ListCell"];
        [_tableV setDelegate:self];
        [_tableV setDataSource:self];
        [self.view addSubview:_tableV];
        [_tableV release];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

//    self.view.backgroundColor = [UIColor whiteColor];

//    UINavigationController *listNav = [[[UINavigationController alloc] initWithRootViewController:self] autorelease];
//    listNav.navigationBar.backgroundColor = [UIColor redColor];
//    [self createList];
}

- (void)createList
{



}


#pragma mark -
#pragma mark 列表回收(通知中心)
- (void)listBack:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"listBack" object:self userInfo:nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

#pragma mark -
#pragma mark 自定义cell(收藏管理,文件管理)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListCell"];
    switch (indexPath.section) {
        case 0:
        {
            if(indexPath.row == 0)
            {
                cell.nameLabel.text = @"最新收藏";
                [cell.imageView setImage:[UIImage imageNamed:@"iconfont-shu.png"]];
                cell.numLabel.text = @"0";
                cell.accessoryType = UITableViewCellAccessoryNone;
            }else{
                cell.nameLabel.text = @"我的下载";
                [cell.imageView setImage:[UIImage imageNamed:@"iconfont-xiazai.png"]];
                cell.numLabel.text = @"0";
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
        }
            break;
            case 1:
        {
            if (indexPath.row == 0) {
                [cell.imageV setImage:[UIImage imageNamed:@"iconfont-iconfontwenjianjia.png"]];
                cell.numLabel.text = @"0";
                [cell.nameLabel setText:@"收藏喜欢"];
                [cell.iconImageView setImage:[UIImage imageNamed:@"iconfont-you.png"]];
            }else{
                [cell.imageV setImage:[UIImage imageNamed:@"iconfont-iconfontwenjianjia.png"]];
                cell.numLabel.text = @"0";
                [cell.nameLabel setText:@"其他类"];
                [cell.iconImageView setImage:[UIImage imageNamed:@"iconfont-you.png"]];
            }

        }
            break;
        default:
            break;
    }
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0f;
}
#pragma mark -
#pragma mark 列表中文件夹
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"listBack" object:self userInfo:nil];
        }else{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"listBack" object:self userInfo:nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"myDownLoad" object:self userInfo:nil];
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {

        }else if (indexPath.row == 1){

        }
    }
}
#pragma mark -
#pragma 自定义section(section高度,我的文件夹,编辑button)

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 64.0f;
    }else{
    return 30.0f;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        {
            UIView *bVeiw = [[[UIView alloc] initWithFrame:CGRectMake(0, 10, self.view.frame.size.width, 60)] autorelease];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

            button.frame = CGRectMake(self.view.frame.size.width - 40, 25, 30, 30);
            [button setImage:[UIImage imageNamed:@"iconfont-fanhui.png"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(listBack:) forControlEvents:UIControlEventTouchUpInside];
            [bVeiw addSubview:button];
            return bVeiw;
        }
            break;
        case 1:
        {
            UIView *aVeiw = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)] autorelease];

            UILabel *folderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 150, 20)];
            [folderLabel setText:@"我的文件夹"];
            [aVeiw addSubview:folderLabel];
            [folderLabel release];

            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            [button setFrame:CGRectMake(270, 0, 30, 20)];
            [button addTarget:self action:@selector(editingFolder) forControlEvents:UIControlEventTouchUpInside];
            [button setTitle:@"编辑" forState:UIControlStateNormal];
            [button setTitle:@"编辑" forState:UIControlStateHighlighted];
            button.titleLabel.textColor = [UIColor blueColor];
            [aVeiw addSubview:button];
            return aVeiw;
        }
            break;
        default:
            break;
    }
    return nil;
}
#pragma mark -
#pragma mark 编辑button 点击进入文件夹管理界面
- (void)editingFolder
{
    CustomNewFolderViewController *cus = [[CustomNewFolderViewController alloc] init];
    [self.navigationController pushViewController:cus animated:YES];
    [cus release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
